/**
 * Created by Administrator on 2019/5/21 0021.
 */

// 在轨迹物体上添加一个带图标的关键点
// idOrbit：轨迹物体对象ID，UUID字符串（包括火箭、车辆等）
// id：该关键点ID，UUID字符串
// relSecs：相对秒数（数据起始时刻）
// name：关键点名字
// description：关键点描述
// MarkerVisible：二维标签是否可见（true/false）
// MarkerPath：二维标签图片路径，字符串
// MarkerPixelSize：二维标签图片大小（1）
// MarkerColor：二维标签颜色，数组：[R,G,B,255]（[255,0,0,255]）
// MarkerXOriginPos：二维标签水平对齐，字符串，三种可选（"CENTER"，"LEFT"，"RIGHT"）
// MarkerYOriginPos：二维标签垂直对齐，字符串，三种可选（"CENTER"，"LEFT"，"RIGHT"）
import CZML_GENERALTOOLS_CLASS from "../main/CZML_GENERALTOOLS_CLASS.js"
import SMAP_LinkedList from "./../utils/SMAP_LinkedList.js"

class CZML_PlaceInOrbitObject {
  constructor(
    viewer,
    idOrbit,
    id,
    relSecs,
    name,
    description,
    MarkerVisible,
    MarkerPath,
    MarkerPixelSize,
    MarkerColor,
    MarkerXOriginPos,
    MarkerYOriginPos
  ) {
    this._viewer = viewer
    this.idOrbit = idOrbit
    this.id = id
    this.relSecs = relSecs
    this.name = name
    this.description = description
    this.MarkerVisible = MarkerVisible
    this.MarkerPath = MarkerPath
    this.MarkerPixelSize = MarkerPixelSize
    this.MarkerColor = MarkerColor
    this.MarkerXOriginPos = MarkerXOriginPos
    this.MarkerYOriginPos = MarkerYOriginPos
    this.AddPlaceInOrbitObject()
  }

  AddPlaceInOrbitObject() {
    const position = CZML_GENERALTOOLS_CLASS.FindModelObjectInformation(this.idOrbit, this.relSecs)
    if (position[0] === null) {
      return false
    }
    // 找到该对象
    const idOrbit = this.idOrbit
    const FindObjectNode = CZML_GENERALTOOLS_CLASS.CzmlList.find(function (node) {
      return node.data().id === idOrbit
    })
    let posNode
    // cartesian格式的数据
    if (FindObjectNode.data().position.cartesian !== undefined) {
      posNode = {
        referenceFrame: FindObjectNode.data().position.referenceFrame,
        cartesian: position
      }
    } else {
      posNode = {
        cartographicDegrees: position
      }
    }
    const PlaceData = {
      id: this.id,
      availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
      name: this.name,
      description: this.description,
      billboard: {
        eyeOffset: {
          cartesian: [0, 0, 0]
        },
        horizontalOrigin: this.MarkerXOriginPos,
        image: this.MarkerPath,
        pixelOffset: {
          cartesian2: [0, 0]
        },
        scale: this.MarkerPixelSize,
        show: this.MarkerVisible,
        verticalOrigin: this.MarkerYOriginPos
      },
      label: {
        fillColor: {
          rgba: this.MarkerColor
        },
        font: "11pt Lucida Console",
        horizontalOrigin: "LEFT",
        pixelOffset: {
          cartesian2: [10, 0]
        },
        show: this.MarkerVisible,
        style: "FILL_AND_OUTLINE",
        text: this.name,
        verticalOrigin: "CENTER"
      },
      position: posNode
    }
    // 插入该数据对象
    const ret = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.id, PlaceData, true)
    // 上图
    CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
    return ret
  }
}

export default CZML_PlaceInOrbitObject
